package com.bs.blogspace.controller;

import com.bs.blogspace.model.Result;
import com.bs.blogspace.pojo.Space;
import com.bs.blogspace.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@RestController
@Slf4j
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result uoload(MultipartFile file) throws IOException {
        log.info("文件上传，文件名:{}",file.getOriginalFilename());
        String url = aliOSSUtils.upload(file);
        log.info("文件上传完成，文件访问的地址：{}",url);
        Result<Object> result = new Result<>();
        result.setCode("200");
        result.setSuccess(true);
        result.setUrl(url);
        return result;
    }
}
